<template>
  <div>provide和inject</div>
  <h1>父组件</h1>
  <p>当前颜色: {{ color }}</p>
  <button @click="color = 'red'">红</button>
  <button @click="color = 'green'">绿</button>
  <button @click="color = 'blue'">蓝</button>
  <hr>
  <Son />
</template>
<script lang="ts">
import { defineComponent, ref, provide } from 'vue'
import Son from './components/Son.vue'
export default defineComponent({
  name: 'App',
  components: {
    Son
  },
  setup() {
    // 响应式数据
    const color = ref('red')
    // 提供数据
    provide('color', color)
    return {
      color
    }
  }
})
</script>